package Offer;

public class Wanshu {
    //1.判断n是否是完数
    public int isWanShu(int n) {
        int sum = 0;
        for (int i = 1; i < n; i++) {
            if (n % i == 0) {
                sum += i;
            }
        }
        if (sum == n)
            return 0;
        else
            return sum;
    }

    //2.输出1000以内所有完数
    public void allWanShu() {
        for (int i = 1; i < 1000; i++) {
            if (isWanShu(i)==0)
                System.out.print(i + ",");
        }
        System.out.println();
    }

    //3.三千以内所有的亲密数
    public void friendShu() {
        for (int i = 1; i < 3000; i++) {
            int sum = isWanShu(i);
            if(isWanShu(sum)==i){
                System.out.println(i+"和"+sum+"是亲密数");
            }
        }
    }


    public static void main(String[] args) {
        //test 1.
        Wanshu wanshu = new Wanshu();
        int b = wanshu.isWanShu(8);
        if (b == 0)
            System.out.println("true");
        else
            System.out.println("false");
        //test 2.
        wanshu.allWanShu();
        //test 3.
        wanshu.friendShu();
    }
}
